﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WebShopAPI.Models;
namespace WebShopAPI.Controllers
{
    /// <summary>
    /// 快递单号操作：在处理订单发货处理时，会保存快递单号，
    /// 利用单号：调用快递公司单号可以查询快递信息
    /// </summary>
    public class kuaidiController : ApiController
    {
        #region 查询快递情况
        public ResponData Get(int id)
        {
            //接收过来的订单编号，查询sp_express表中对应单号的快递公司与快递号

            //利用单号调用网上的api查询出物流信息
            //暂时假设一下数据
            List<KDInfo> kdList = new List<KDInfo>();
            kdList.Add(new KDInfo
            {
                time = "2018-07-10 09:39:00",
                ftime = "2018-07-10 09:39:00",
                context = "已签收,感谢使用顺丰,期待再次为您服务",
                location = ""
            });
            kdList.Add(new KDInfo
            {
                time = "2018-06-10 09:39:00",
                ftime = "2018-06-10 09:39:00",
                context = "已到长沙",
                location = ""
            });
            kdList.Add(new KDInfo
            {
                time = "2018-05-10 09:39:00",
                ftime = "2018-05-10 09:39:00",
                context = "已到湖北",
                location = ""
            });
            kdList.Add(new KDInfo
            {
                time = "2018-04-10 09:39:00",
                ftime = "2018-04-10 09:39:00",
                context = "下单成功",
                location = ""
            });
            //
            ResponData rd = new ResponData();
            if (kdList.Count > 0)
            {
                rd.data = kdList;
                rd.meta.status = 200;
                rd.meta.msg = "获取成功";
            }
            else 
            {
                rd.data = null;
                rd.meta.status = 201;
                rd.meta.msg = "获取失败，末收集到信息";
            }
            return rd;
        }
        #endregion
    }

    /// <summary>
    /// 定义一个物流信息类
    /// </summary>
    public class KDInfo
    { 
        public string time { get; set; }
        public string ftime { get; set; }
        public string context { get; set; }

        public string location { get; set; }
    }
}
